package com.derbysoft.lowcostadapter.web.action.admin.cachemanager;

import com.derbysoft.lowcostadapter.schedule.sync.SyncFtpFilesService;
import com.derbysoft.lowcostadapter.web.action.BaseAdapterAction;
import org.apache.struts2.convention.annotation.Action;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

/**
 * Created by: jason
 * Date: 2012-10-22
 */
public class ReDoScheduleAction extends BaseAdapterAction {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    @Qualifier("syncFtpFilesService")
    private SyncFtpFilesService syncService;

    @Action("redoSchedule")
    public void redoSchedule() {
        try {
            logger.info("begin sync ..");
            if (syncService.isRunning()) {
                logger.info("syncService is running ..");
                populateSucceededJsonResult("syncService is running ..");
            } else {
                syncService.syncEnforce();
                populateSucceededJsonResult("redo done !!");
            }
        } catch (Exception e) {
            populateFailedJsonResult(e);
        }
    }
}
